﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using XiAnAirport.BUS;
using XiAnAirport.BUS.Escalator;
using XiAnAirport.Models;

namespace XiAnAirport.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize]
    public class EscalatorController : ControllerBase
    {
        public EscalatorController()
        {
        }

        [HttpGet]
        [HttpPost]
        [Route("GetFileNameByTime")]
        public EscalatorResponseMessage GetFileNameByTime(string datetTime, int elevatorid, string partName)
        {
            EscalatorResponseMessage response = new EscalatorResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetAllDataByTime(datetTime, elevatorid, partName);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }


        [HttpGet]
        [HttpPost]
        [Route("GetAllFileNameByTimeRange")]
        public EscalatorResponseMessage2 GetAllFileNameByTimeRange(string startTime,string endTime, int elevatorid, string partName)
        {
            EscalatorResponseMessage2 response = new EscalatorResponseMessage2();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetAllFileNameByTimeRange(startTime, endTime, elevatorid, partName);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }


        [HttpGet]
        [HttpPost]
        [Route("GetDeviceSns")]
        public DeviceSnsResponseMessage GetDeviceSns(int elevatorid)
        {
            DeviceSnsResponseMessage response = new DeviceSnsResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetDeviceSns( elevatorid);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }

        [HttpGet]
        [HttpPost]
        [Route("GetAlarmAndWarn")]
        public ConfigParamModelResponseMessage GetAlarmAndWarn(int elevatorid, string device_sn)
        {
            ConfigParamModelResponseMessage response = new ConfigParamModelResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetAlarmAndWarn(elevatorid,device_sn);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }

        [HttpGet]
        [HttpPost]
        [Route("GetWarns")]
        public WarnsResponseMessage GetWarns(int elevatorid)
        {
            WarnsResponseMessage response = new WarnsResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetWarns(elevatorid);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }

        [HttpGet]
        [HttpPost]
        [Route("GetAlarms")]
        public WarnsResponseMessage GetAlarms(int elevatorid)
        {
            WarnsResponseMessage response = new WarnsResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetAlarms(elevatorid);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }

        [HttpGet]
        [HttpPost]
        [Route("GetDeviceListNames")]
        public ConfigModelResponseMessage GetDeviceListNames(int elevatorid, string deviceNames)
        {
            ConfigModelResponseMessage response = new ConfigModelResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetDeviceListNames(elevatorid,deviceNames);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }
        
        [HttpGet]
        [HttpPost]
        [Route("GetPartNames")]
        public ConfigModelResponseMessage GetPartNames(int elevatorid)
        {
            ConfigModelResponseMessage response = new ConfigModelResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetPartNames(elevatorid);
            }
            catch (Exception ex)
            {
                response.errcode = 1;
                response.errmsg = ex.Message;
            }
            return response;
        }

        [HttpGet]
        [HttpPost]
        [Route("GetDatasByFileName")]
        public ChannelDataResponseMessage GetDatasByFileName(int elevatorid, string path)
        {
            ChannelDataResponseMessage response = new ChannelDataResponseMessage();
            try
            {
                EscalatorBUS escalatorBUS = new EscalatorBUS();
                response = escalatorBUS.GetDatasByFileName(elevatorid,path);
            }
            catch (Exception ex)
            {
              
            }
            return response;
        }
    }
}
